<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        .container {
            margin: 100px;
            padding: 100px;
            width: 400px;
            height: 400px;
            background-color: pink;
            border: 50px solid #ccc;
            position: relative;
        }
        
        .inner {
            width: 300px;
            height: 300px;
            background-color: yellow;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: green;
            /* 如果父元素设置了定位那么就相对于其定位 */
            /* 绝对定位 */
            position: absolute;
            left: 100px;
            top: 100px;
        }
        span {
            /* 压盖现象，后设置定位的元素会压在先设置定位的元素上 */
            width: 100px;
            height: 100px;
            /* 设置了绝对定位，display失效 */
            display: block;
            background-color:yellowgreen;
            position: absolute;
            left: 50%;
            top: 50%;
            /* 元素居中 */
            margin: -50px -50px;
        }
        /* 定位居中 */
        .box1 {
            width: 400px;
            height: 400px;
            background-color: skyblue;
            position: absolute;
            left: 50%;
            top: 50%;
            margin: -200px -200px;
        }
    </style>
</head>
<body>
    <!-- 盒子嵌套 -->
    <div class="container">
        <div class="inner">
            <div class="box"></div>
            <span>span</span>
        </div>
    </div>
    <div class="box1">
    </div>
</body>
</html>